package com.crm.reports;

import java.awt.Desktop;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.JOptionPane;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRBeanArrayDataSource;
import net.sf.jasperreports.engine.util.JRLoader;

import org.apache.log4j.Logger;

import com.crm.beans.QuotParts;


public class JRProformaInvoice {
	public static void main(String[] args) throws Exception{
		  Map<String,String> parameters = new HashMap<String,String>();
		  parameters.put("invoiceno", "KK/CP/1/12-09-2012");
		  parameters.put("sonumber", "1234");
		  parameters.put("sodate", "12/06/2011");
		  parameters.put("priceword", "Ten Thousand Rupees Only");
		  parameters.put("billto", "#2-40 \n" +
		  		"AnandBagh, \n" +
		  		"Malkajgiri \n" +
		  		"Secunderabad \n" +
		  		"500072");
		  parameters.put("shipto","#2-40 \n" +
		  		"AnandBagh, \n" +
			  		"Malkajgiri \n" +
			  		"Secunderabad \n" +
			  		"500072");
		  parameters.put("tinno", "123456");
		  parameters.put("cstno", "7891011");
		  parameters.put("panno", "ABCDEF1234G");
		  parameters.put("terms", "1 Vat @4% EXTRA.\n" +
				  "2 Validity: 30DAYS \n" +
				  "3 Waranty: NOT APPLICABLE\n" +
				  "4 Payment:  100% within 15 Days from the date of receipt of material at your stores,else interest @ 2.5%/month needs to be paid by your organisation\n" +
				  "5  Prices are valid for quoted quantities only.\n" +
				  "6  Quoted lead time is as of now only.\n" +
				  "7 Order should be placed on: KK Circuits & equipments\n"+
				  "8 Order should be placed on: KK Circuits & equipments\n"+
				  "9 Order should be placed on: KK Circuits & equipments\n"+
				  "10 Order should be placed on: KK Circuits & equipments\n"+
				  "11 Order should be placed on: KK Circuits & equipments\n"+
				  "12 Order should be placed on: KK Circuits & equipments\n"+
				  "13 Order should be placed on: KK Circuits & equipments\n"+
				  "14 Order should be placed on: KK Circuits & equipments\n"+
				  "15 Order should be placed on: KK Circuits & equipments\n"+
				  "16 Order should be placed on: KK Circuits & equipments\n"+
				  "17 Order should be placed on: KK Circuits & equipments\n"+
				  "18 Order should be placed on: KK Circuits & equipments\n"+
				  "19 Order should be placed on: KK Circuits & equipments\n"+
				  "20 Order should be placed on: KK Circuits & equipments\n"+
				  "21 Order should be placed on: KK Circuits & equipments\n"+
				  "22 Order should be placed on: KK Circuits & equipments\n"+
				  "23 Order should be placed on: KK Circuits & equipments\n"+
				  "24 Order should be placed on: KK Circuits & equipments\n"+
				  "25 Order should be placed on: KK Circuits & equipments\n"+
				  "26 Order should be placed on: KK Circuits & equipments\n"+
				  "27 Order should be placed on: KK Circuits & equipments\n"+
				  "28 Order should be placed on: KK Circuits & equipments\n"+
				  "29 Order should be placed on: KK Circuits & equipments\n"+
				  "30 Order should be placed on: KK Circuits & equipments\n"+
				  "31 Order should be placed on: KK Circuits & equipments\n"+
				  "32 Order should be placed on: KK Circuits & equipments\n"/*+
				  "33 Order should be placed on: KK Circuits & equipments\n"+
				  "34 Order should be placed on: KK Circuits & equipments\n"+
				  "35 Order should be placed on: KK Circuits & equipments\n"+
				  "36 Order should be placed on: KK Circuits & equipments\n"+
				  "37 Order should be placed on: KK Circuits & equipments\n"+
				  "38 Order should be placed on: KK Circuits & equipments\n"+
				  "39 Order should be placed on: KK Circuits & equipments\n" +
				  "40 Order should be placed on: KK Circuits & equipments\n" +
				  "41 Order should be placed on: KK Circuits & equipments\n" +
				  "42 Order should be placed on: KK Circuits & equipments\n" +
				  "43 Order should be placed on: KK Circuits & equipments\n" +
				  "44 Order should be placed on: KK Circuits & equipments\n" +
				  "45 Order should be placed on: KK Circuits & equipments\n"*/);
		  parameters.put("from", "KK Circuits And Equipments");
		  parameters.put("manager", "Sainath reddy \n" +
		  		"Manager Operations");
		  parameters.put("subtotal", "2000");
		  parameters.put("vat", "1000");
		  parameters.put("total", "10000");
		  
		  List<QuotParts> l=new ArrayList<QuotParts>();
		  
		  QuotParts qp=new QuotParts();
		  qp.totalcost="1000";
		  qp.sno="1";
		  qp.partNo="er2323";
		  qp.desc="desc";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.totalcost="1000";
		  qp.sno="2";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.totalcost="1000";
		  qp.sno="3";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.totalcost="1000";
		  qp.sno="4";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.totalcost="1000";
		  qp.sno="5";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.totalcost="1000";
		  qp.sno="6";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.totalcost="1000";
		  qp.sno="7";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.totalcost="1000";
		  qp.sno="8";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.totalcost="1000";
		  qp.sno="9";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.totalcost="1000";
		  qp.sno="10";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.totalcost="1000";
		  qp.sno="11";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.totalcost="1000";
		  qp.sno="12";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.totalcost="1000";
		  qp.sno="13";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.totalcost="1000";
		  qp.sno="14";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.totalcost="1000";
		  qp.sno="15";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.totalcost="1000";
		  qp.sno="16";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.totalcost="1000";
		  qp.sno="17";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.totalcost="1000";
		  qp.sno="18";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.totalcost="1000";
		  qp.sno="19";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.totalcost="1000";
		  qp.sno="20";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.totalcost="1000";
		  qp.sno="21";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  l.add(qp);
		  
		runReport("D:/work/crmWeb/WebContent/WEB-INF/classes/reports/ProInvoice.jasper", parameters, l.toArray());
		
		}
	
	public static void runReport(String inname,Map<String, String> parms, Object[] prtArry) throws JRException, IOException {
		long start = System.currentTimeMillis();
		 
		JasperReport techreport = (JasperReport) JRLoader.loadObject(inname);

		
		JasperPrint print = JasperFillManager.fillReport(techreport,parms,new JRBeanArrayDataSource(prtArry));
		 OutputStream output=new FileOutputStream(new File("proformainvoice.pdf"));
		 
		JasperExportManager.exportReportToPdfStream(print,output);
		//JasperExportManager.exportReportToHtmlFile(print,"proformainvoice.html");
		
		output.close();
		
		Desktop.getDesktop().open(new File("proformainvoice.pdf"));
		System.err.println("Filling time : " + (System.currentTimeMillis() - start));
	}
}
